import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
let storePlayList = [];
try {
let value = uni.getStorageSync("playList");
  if (value) {
storePlayList = JSON.parse(value);
  }
} catch (e) {}

export default new Vuex.Store({
  state: {
    userInfo: {
      Login: false,
      // hasLogin:true
      leaveTime: 0, //记录app隐藏的时间
      playList: storePlayList,
    },
  },
  mutations: {
    //记录app隐藏的开始时间
    storeLeaveTime(state, payload) {
      let curTime = new Date().getTime();
      state.leaveTime = curTime;
    },
    // 存储用户信息
    storeLogin(state, data) {
      state.userInfo.Login = data;
      uni.setStorageSync("userLogin", JSON.stringify(state.userInfo));
    },
    // 清除用户信息
    setLoginStatic(state, value) {
      state.userInfo.Login = value;
    },
    storePlayList(state, data) {
      state.playList = data;
      uni.setStorageSync("playList", JSON.stringify(data));
    },
  },
  Action: {},
  Getter: {},
});
